package com.yswl.yeeduo.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.umeng.analytics.MobclickAgent;
import com.yswl.yeeduo.App;
import com.yswl.yeeduo.R;
import com.yswl.yeeduo.tool.KLog;
import com.yswl.yeeduo.ui.base.BaseWebViewActivity;
import com.yswl.yeeduo.ui.bean.ActiviteDetailBean;
import com.yswl.yeeduo.view.dialog.SelectSharePopupDialog;

/**
 * 本类集成BaseWebViewActivity 有关打开网页的参数在BaseWebViewActivity createIntent()中传入所需的参数
 * 在此需求有需要微信分享功能 参数来自 本类的createIntent();
 * 
 * @author Administrator
 *
 */
public class WebViewActivity extends BaseWebViewActivity {
	public static Intent createIntent(Context context, ActiviteDetailBean bean, boolean isLanscape, boolean hideNav) {
		Intent returnIntent = BaseWebViewActivity.createIntent(context, bean.url, bean.agentName, isLanscape, hideNav,WebViewActivity.class);
		returnIntent.putExtra("bean", bean);
		return returnIntent;
	}
	
	private ActiviteDetailBean bean;
	@Override
	public int loadView_Lanscape() {
		return R.layout.activity_webview;
	}

	@Override
	public int loadView() {
		return R.layout.activity_webview;
	}

	@Override
	public void initView() {
		bean = (ActiviteDetailBean) getIntent().getSerializableExtra("bean");

		super.mTitle = (TextView) super.findViewById(R.id.nav_title);
		super.mBack = (ImageView) super.findViewById(R.id.nav_left);
		mBack.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		this.webView = (WebView) super.findViewById(R.id.web_view);
		super.mLayout = (RelativeLayout) webView.getParent();

		final LinearLayout showTag = (LinearLayout) super.findViewById(R.id.ll_shareTag);
		showTag.setVisibility(View.VISIBLE);
		LinearLayout closeTag = (LinearLayout) super.findViewById(R.id.ll_shareTagCloseBtn);
		closeTag.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (showTag.getVisibility() == View.VISIBLE) {
					showTag.setVisibility(View.GONE);
				}
			}
		});

		ImageView shareIv = (ImageView) super.findViewById(R.id.iv_share_btn);
		shareIv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 此处分享
				KLog.e("WebViewActivity", "分享按钮点击");
				if (App.getInstance().isLogin == false) {
					startActivity(new Intent(WebViewActivity.this, LoginActivity.class));
					return;
				}
				if (bean != null ) {
					SelectSharePopupDialog dialog = new SelectSharePopupDialog(WebViewActivity.this);
					dialog.setActiveBean(bean); 
					dialog.showAtLocation(mLayout, Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0); //设置layout在PopupWindow中显示的位置
				}
			}
		});

	}


	/**
	 * 友盟统计
	 */
	public void onResume() {
		super.onResume();
		MobclickAgent.onPageStart(this.getClass().getSimpleName());
		MobclickAgent.onResume(this); // 统计时长
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPageEnd(this.getClass().getSimpleName());
		MobclickAgent.onPause(this);
	}
}
